package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.mapper.OrderTypeMapper;
import com.ruoyi.system.domain.OrderType;
import com.ruoyi.system.service.IOrderTypeService;

/**
 * 订单类型Service业务层处理
 *
 * @author trip
 * @date 2024-09-20
 */
@Service
public class OrderTypeServiceImpl extends ServiceImpl<OrderTypeMapper, OrderType> implements IOrderTypeService {

    @Autowired
    private OrderTypeMapper orderTypeMapper;

    /**
     * 查询订单类型
     *
     * @param orderTypeId 订单类型主键
     * @return 订单类型
     */
    @Override
    public OrderType selectOrderTypeByOrderTypeId(Long orderTypeId) {
        return orderTypeMapper.selectOrderTypeByOrderTypeId(orderTypeId);
    }

    /**
     * 查询订单类型列表
     *
     * @param orderType 订单类型
     * @return 订单类型
     */
    @Override
    public List<OrderType> selectOrderTypeList(OrderType orderType) {
        return orderTypeMapper.selectOrderTypeList(orderType);
    }

    /**
     * 新增订单类型
     *
     * @param orderType 订单类型
     * @return 结果
     */
    @Override
    public int insertOrderType(OrderType orderType) {
                orderType.setCreateTime(DateUtils.getNowDate());
            return orderTypeMapper.insertOrderType(orderType);
    }

    /**
     * 修改订单类型
     *
     * @param orderType 订单类型
     * @return 结果
     */
    @Override
    public int updateOrderType(OrderType orderType) {
                orderType.setUpdateTime(DateUtils.getNowDate());
        return orderTypeMapper.updateOrderType(orderType);
    }

    /**
     * 批量删除订单类型
     *
     * @param orderTypeIds 需要删除的订单类型主键
     * @return 结果
     */
    @Override
    public int deleteOrderTypeByOrderTypeIds(Long[] orderTypeIds) {
        
            LambdaUpdateWrapper<OrderType> wrapper;
            for (Long id : orderTypeIds) {
                wrapper = Wrappers.lambdaUpdate(OrderType.class)
                .eq(OrderType::getOrderTypeId, id)
                    .set(OrderType::getDelFlag, "1");
                super.update(new OrderType(), wrapper);
            }
            return 1;
    }

    /**
     * 删除订单类型信息
     *
     * @param orderTypeId 订单类型主键
     * @return 结果
     */
    @Override
    public int deleteOrderTypeByOrderTypeId(Long orderTypeId) {
        return orderTypeMapper.deleteOrderTypeByOrderTypeId(orderTypeId);
    }
}



